# SET DIRECTORY TO SOURCE FILE 

# RUN fig4-gen-predicted-probabilities.do FIRST
# Save predicted probabilities to data/cleaned/fig4data.csv


library(ggplot2)

data <- read.csv("../../data/cleaned/fig4data.csv", stringsAsFactors = FALSE)
  #these predicted probabilities are generated by fig4-gen-predicted-probabilities.do

data$SIG.Aligned <- paste0('Respondent Shown\nRating From\n', data$SIG.Aligned, ' SIG')
data$SIG.Aligned <- factor(data$SIG.Aligned, ordered = TRUE, levels = unique(data$SIG.Aligned)[c(2,1)])
data$Study <- paste0('Study ', data$Study)

pd <- position_dodge(width = 0.45)
plot <- ggplot(data, aes(x=SIG.Aligned, y=Coef, group=Rating, color=Rating)) + 
  geom_point(position = pd) +
  geom_errorbar(aes(ymin = Coef-1.96*SE, ymax = Coef+1.96*SE),
                width = 0,
                position = pd) +
  scale_color_manual(values = c('salmon', 'chartreuse4'), name = 'Rating Shown to Respondent...') +
  ylab("Mean of MC Approval Scale") +
  xlab('') +
  #xlab("SIG Aligned or Misaligned with Respondent?") +
  ggtitle("Mean of MC Approval Scale by Experimental Condition") + 
  facet_wrap(~Study) +
  theme_bw() + theme(legend.position = 'bottom') +
  coord_flip()
plot

ggsave("../figures/fig4.pdf", plot, width = 6.5, height = 3.5, scale = 1)

